﻿#SingleInstance, Force
#NoEnv
SetBatchLines, -1
CoordMode, Pixel, Screen
CoordMode, Mouse, Screen

#Include <Gdip>
; #Include Gdip.ahk

gosub 初始化

SetTimer, 显示当前颜色, 20
return

LButton::
	Critical
	SetTimer, 显示当前颜色, Off
	Gdip_GraphicsClear(G) ;清空画布
	Clipboard := "#" SubStr(color,3)
	ExitApp
Return

$esc::
	SetTimer, 显示当前颜色, Off
	ExitApp
Return

显示当前颜色:


	Gdip_GraphicsClear(G) ;清空画布

	MouseGetPos, x, y
	PixelGetColor, color, x, y, RGB
	
	if (x > Width-220)
		x-=220
	else
		x+=20
	if (y > Height-120)
		y-=120
	else
		y+=20
	

	o_color:= "0xff" SubStr(color,3) ;获取颜色

	if (color > 0x800000) ;偏深色
	{
		b_color:=0xaa000000
		t_color:="FFFFFFFF"
	}
	else ;偏浅色
	{
		b_color:=0xaaffffff
		t_color:="FF000000"
	}	
	
	pBrush := Gdip_BrushCreateSolid(b_color) ;背景笔刷
	Gdip_FillRectangle(G, pBrush, x, y, 200, 60) ;背景
	Gdip_DeleteBrush(pBrush)
	
	pBrush := Gdip_BrushCreateSolid(o_color) ;色块笔刷
	Gdip_FillRectangle(G, pBrush, x+5, y+5, 50, 50) ;色块
	Gdip_DeleteBrush(pBrush)

	Gdip_TextToGraphics(G, "#" SubStr(color,3) "`n点击取色", "x" x+60 " y" y+5 "s22 c" t_color)

	UpdateLayeredWindow(hwnd1, hdc, 0, 0, Width, Height) ;更新图
	

	return


初始化:
	If !pToken := Gdip_Startup()
	{
		MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
		ExitApp
	}
	OnExit, GdipExit

	Gui, 1: -Caption +E0x80000 +LastFound +AlwaysOnTop +ToolWindow +OwnDialogs
	Gui, 1: Show, NA
	hwnd1 := WinExist()

	Width :=A_ScreenWidth, Height := A_ScreenHeight
	hbm := CreateDIBSection(Width, Height) ;全屏大小的位图

	hdc := CreateCompatibleDC()
	obm := SelectObject(hdc, hbm)

	G := Gdip_GraphicsFromHDC(hdc)
	Gdip_SetSmoothingMode(G, 0) ;不消除画笔锯齿
return



GuiClose:
GuiEscape:
GdipExit:
	Gdip_DeletePen(pPen)

	Gdip_DeleteGraphics(G)
	SelectObject(hdc, obm)
	DeleteDC(hdc)
	DeleteObject(hbm)
	Gdip_Shutdown(pToken)
	ExitApp
Return